/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.skill.executor;

import static com.lineage.server.model.skill.L1SkillId.STATUS_FREEZE;
import static com.lineage.server.model.skill.L1SkillId.THUNDER_GRAB_START;

import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Magic;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillExecutor;
import com.lineage.server.packetserver.S_Paralysis;
import com.lineage.server.packetserver.S_SkillSound;
import com.lineage.server.packetserver.ServerBasePacket;

/**
 * Class <code>ThunderGrab</code> 龙骑士魔法:夺命之雷 (0/45/0).
 * 召唤黑暗落雷攻击前方1~4个目标造成伤害28~44点。
 * 有60%机率产生束缚1~4秒。
 * 
 * 目标受到束缚的成功率，受到目标等级和支撑耐性的影响
 * 
 * @author jrwz
 * @version 2012-7-26上午10:32:54
 * @see com.lineage.server.model.skill.executor
 * @since JDK1.7
 */
public final class ThunderGrab extends L1SkillExecutor {

    /** 黑暗落雷效果. */
    private static final int EFFECT = 4184;

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static L1SkillExecutor get() {
        return new ThunderGrab();
    }

    /** 是否成功. */
    private boolean isSuccess;
    /** 技能. */
    private L1Magic magic;

    /** 龙骑士魔法:夺命之雷 (0/45/0). */
    private ThunderGrab() {
    }

    @Override
    public void execute(final L1Character user, final L1Character cha,
            final L1Character target, final int targetID, final int skillId,
            final int getBuffIconDuration) {
        this.magic = new L1Magic(user, cha);
        this.isSuccess = this.magic.calcProbabilityMagic(skillId);
        if (this.isSuccess) {
            if (!cha.hasSkillEffect(THUNDER_GRAB_START)
                    && !cha.hasSkillEffect(STATUS_FREEZE)) {
                ServerBasePacket msg;
                if (cha instanceof L1PcInstance) {
                    final L1PcInstance pc = (L1PcInstance) cha;
                    msg = new S_Paralysis(S_Paralysis.TYPE_BIND, true);
                    pc.sendPackets(msg);
                    msg = new S_SkillSound(pc.getId(), EFFECT);
                    pc.sendPackets(msg);
                    pc.broadcastPacket(msg);
                } else if (cha instanceof L1NpcInstance) {
                    final L1NpcInstance npc = (L1NpcInstance) cha;
                    npc.setParalyzed(true);
                    msg = new S_SkillSound(npc.getId(), EFFECT);
                    npc.broadcastPacket(msg);
                }
                cha.setSkillEffect(THUNDER_GRAB_START, 500);
            }
        }
    }

    @Override
    public void stop(final L1Character cha, final int skillId) {
        // TODO Auto-generated method stub
    }
}
